package com.midea.ai.air.ui.device.product;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseActivity;
import com.midea.ai.air.ui.device.product.airconditioner.AirPurifierFragment;
import com.midea.ai.air.ui.device.product.data.DeviceInfo;
import com.midea.ai.air.ui.device.product.airconditioner.AircBaseFragment;

import java.util.ArrayList;

/**
 * Created by tanchuo on 16/3/21.
 */
public class DeviceMainActivity extends BaseActivity
{
    private int tag;

    public static void startDeviceAct(Context context,int tag)
    {
        Intent intent = new Intent(context,DeviceMainActivity.class);
        intent.putExtra("tag",tag);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_device_main);

        if (getIntent() != null)
        {
            tag = getIntent().getIntExtra("tag",0);
        }

        initFragment(tag);
    }

    private void initFragment(int tag)
    {
        switch (tag)
        {
            case DeviceInfo.AIRC_TAG:  //空调
                AircBaseFragment aircBaseFragment = new AircBaseFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.device_main_container, aircBaseFragment,"AircBaseFragment").commit();

                break;
            case DeviceInfo.AIRP_TAG:  //净化器
                AirPurifierFragment airPurifierFragment = new AirPurifierFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.device_main_container, airPurifierFragment,"AirPurifierFragment").commit();

                break;
            case DeviceInfo.HUMI_TAG:  //加湿器

                break;
            case DeviceInfo.DEHU_TAG:  //除湿器
                DehumBaseFragment dehumBaseFragment = new DehumBaseFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.device_main_container, dehumBaseFragment,"DehumFragment").commit();
                break;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        // TODO Auto-generated method stub
        for ( MyOntouchListener listener : touchListeners )
        {
            listener.onTouchEvent( event );
        }

        return super.onTouchEvent( event );
    }

    private ArrayList<MyOntouchListener> touchListeners = new ArrayList<DeviceMainActivity.MyOntouchListener>();


    public void registerListener(MyOntouchListener listener)
    {
        touchListeners.add(listener);
    }


    public void unRegisterListener(MyOntouchListener listener)
    {
        touchListeners.remove( listener );
    }

    public interface MyOntouchListener
    {
        public void onTouchEvent(MotionEvent event);
    }
}
